/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.lis.model.newmodel;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import java.util.Date;
import java.util.List;

/**
 *
 * @author cxhd
 */
public class LisCharginitem extends Model<LisCharginitem>{
   public static LisCharginitem lisCharginitemdao=new LisCharginitem();
      
    public void deleteLisCharginitem(String PK){
         Db.use("mysql").update("delete from lis_charginitem where PK=?",Integer.valueOf(PK));
        
     }
     
     public void saveLisCharginitem(String ITEMNAME,String PRICE){  
//         PK,ITEMID,ITEMNAME,PRICE DATA1 lis_charginitem
                set("ITEMID", getItemid())
         .set("ITEMNAME", ITEMNAME)               
                 .set("PRICE", PRICE)
                 .set("DATA1", new Date())
                 .save();
     }
     public void updateLisCharginitem(String PK,String ITEMNAME,String PRICE){
         if(PRICE==""){
             PRICE="0";
         }
         findById(PK)           
                 .set("ITEMNAME", ITEMNAME)
                 .set("PRICE", PRICE)
                 .update();
                 
     }
   
     public String getItemid(){
           List<Record> list=Db.use("mysql").find("select * from lis_charginitem limit 0,10");
        String  value = "1";
        if(list.size()>0){
           value = (Integer.parseInt(Db.use("mysql").findFirst("SELECT MAX(ITEMID) as id from lis_charginitem ").get("id") + "") + 1) + "";
        }
      return value;
      } 
     /**
      * 用于该收费项目所属小项目数量变化时导致的金额变化
      */
     public void updatePrice(String PK,String PRICE){
         findById(PK)
                 .set("PRICE",PRICE).update();
     }
}
